import { ApiExtraModel, ApiProperty, getSchemaPath } from '@midwayjs/swagger';
import { Rule, RuleType } from '@midwayjs/validate';
import { ApiRes, PhoneDto, CodeDto, PaginationDto } from '.';
export class UserLoginReq extends PhoneDto {
  @ApiProperty({ description: '验证码-6位', required: true })
  @Rule(RuleType.number().required().error(new Error('验证码不能为空')))
  code: number;
}
export class UserLoginRes {
  @ApiProperty({ description: 'token' })
  token: string;
}
export class UserLoginResDto extends ApiRes<UserLoginRes>(UserLoginRes) {}

export class UserCodeResDto extends ApiRes<CodeDto>(CodeDto) {}

export class AdminLoginReq {
  @ApiProperty({ description: '账号', required: true })
  @Rule(RuleType.string().required().error(new Error('账号不能为空')))
  account: string;

  @ApiProperty({ description: '密码', required: true })
  @Rule(RuleType.string().required().error(new Error('密码不能为空')))
  pwd: string;
}

export interface AdminLoginRes {
  id: number;
  account: string;
  pwd: string;
}

export enum Gender {
  Woman = 0,
  Man = 1,
}

export class UpdateUserReq {
  @ApiProperty({ description: '业主昵称' })
  nickName: string;

  @ApiProperty({ description: '用户头像' })
  avatar: string;

  @ApiProperty({ description: '业主姓名' })
  name: string;

  @ApiProperty({
    description: '业主性别0女1男',
    default: Gender.Man,
  })
  gender: Gender;
}

export class UserDetailsDto extends ApiRes<UpdateUserReq>(UpdateUserReq) {}

export class UserItem extends UpdateUserReq {
  @ApiProperty({ description: '用户id' })
  id: number;

  @ApiProperty({ description: '用户手机号' })
  phone: number;
}

@ApiExtraModel(UserItem)
export class UserItemRes {
  @ApiProperty({
    type: 'array',
    items: {
      $ref: getSchemaPath(UserItem),
    },
  })
  list: UserItem[];
  @ApiProperty({ type: PaginationDto, description: '分页' })
  pagination: PaginationDto;
}
export class UserItemResDto extends ApiRes<UserItemRes>(UserItemRes) {}
